import { defineStore } from 'pinia'

/* 购物车 */
export default defineStore('matterStore', {
	state() {
		return {
			id: null,
			name: '',
			exam: 0,
			unit_id: 0,
			unit_name: '',
			cate_id: 0,
			home: 0,
			brand_id: 0,
			brand_name: '',
			shelf_life: '',
			is_mult: 0, 
			attrs: [], // 当期商品的属性
			intro: '',
			desc: '',
			gallery: [],  // 相册
			specs: [],  // 当前商品的规格
			items: [{spec:'', barcode:'',soids:[]}]
		}
	},
	actions: {
    init() {
			Object.assign(this, {
				id: null,
				name: '',
				exam: 0,
				unit_id: 0,
				unit_name: '',
				cate_id: 0,
				home: 0,
				brand_id: 0,
				brand_name: '',
				shelf_life: '',
				is_mult: 0, 
				attrs: [], // 当期商品的属性
				intro: '',
				desc: '',
				gallery: [],  // 相册
				specs: [],  // 当前商品的规格
				create_at: null,
				items: [{spec:'', barcode:'',soids:[]}]
			})
    },
    update(values: object) {
      console.log(values)
			Object.assign(this, values)
    }
	},
	persist: {
		// enabled: true,
		// 调整为兼容多端的API
		storage: {
			getItem(key: string) {
				return uni.getStorageSync(key)
			},
			setItem(key: string, value: any) {
				uni.setStorageSync(key, value)
			}
		}
	}
})
